package com.wangzhenyu.learn.test.designPattern


//享元模式


@Suppress("UNUSED")
object LFlyweightPattern {


    abstract class WebSite {

        abstract fun use(user: User)

    }


    class ConcreteWebSite(private val type: String) : WebSite() {

        override fun use(user: User) {

            println("网站的发布形式： $type  ${user.name} 在使用")
        }
    }

    class WebSiteFactory {

        private val pool = mutableMapOf<String, ConcreteWebSite>()

        fun getWebSiteCategory(type: String): WebSite {
            if (!pool.containsKey(type)) {
                pool[type] = ConcreteWebSite(type)
            }
            return pool[type] as WebSite
        }

        fun getWebSiteCount(): Int {
            return pool.size
        }

    }

    class User(var name: String) {

    }

}